import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

X = [52,19,7,33,2]
Y = [162,61,22,100,6]
# X=[
#     12.5, 15.3, 23.2, 26.4, 33.5, 
#     34.4, 39.4, 45.2, 55.4, 60.9]
# Y=[
#     21.2, 23.9, 32.9, 34.1, 42.5, 
#     43.2, 49.0, 52.8, 59.4, 63.5]
# X = [2,19,7,33,2]
# Y = [62,61,22,100,6]

#公式计算
#均值
XMean = np.mean(X)
YMean = np.mean(Y)

#标准差
XSD = np.std(X)
YSD = np.std(Y)

#z分数
ZX = (X-XMean)/XSD
ZY = (Y-YMean)/YSD

#相关系数
r = np.sum(ZX*ZY)/(len(X))

t=np.corrcoef(X,Y)

print('X:\n',X)
print('Y:\n',Y)
print('XMean:\n', XMean)
print('YMean:\n', YMean)
print('XSD:\n', XSD)
print('YSD:\n', YSD)
print('ZX:\n', ZX)
print('ZY:\n', ZY)
print('r:\n',r)
print('t:\n',t)